class Solution {
public:
    int lastStoneWeight(vector<int>& stones) {
        priority_queue<int> p;
        for(auto& x:stones) p.push(x);
        while(p.size()>=2)
        {
            int a=p.top(); 
            p.pop();
            int b=p.top();
            p.pop();
            if(a>b) 
                p.push(a-b);
        }
        if(p.size()!=0) return p.top();
        else return 0;
    }
};
